<template>
  <div>
    <h2 style="color: gray;">申请列表</h2>
    <el-divider></el-divider>
    <!-- 搜索框 -->
    <div style="margin-top: 15px; margin-left: 70%; width: 300px;">
     <el-input placeholder="请输入搜索姓名" v-model="name" @keyup.native.enter="search" class="input-with-select">
        <el-button slot="append" icon="el-icon-search" @click=" search"></el-button>
      </el-input>
    </div>
     

    <!-- 表格 -->
    <template>
      <el-table
        :data="apply"
        style="width: 100%">
        <el-table-column
          prop="apply_id"
          label="编号"
          align="center"
          width="100">
        </el-table-column>
        <el-table-column
          prop="name"
          label="姓名"
          align="center"
         >
        </el-table-column>
        <el-table-column
          prop="phone"
          label="电话号"
          align="center">
        </el-table-column>
        <el-table-column
          prop="isno"
          label="是否自愿"
          align="center">
        </el-table-column>
        <el-table-column
          prop="position"
          label="职位"
          align="center">
        </el-table-column>
          <el-table-column width="300px" align="center" label="操作">
          <template slot-scope="scope">
            <el-button size="small" type="success"  circle icon="el-icon-user" @click="$router.push(`/htlogin/user-details/${scope.row.user_id}`)" ></el-button>
            <el-button size="small" type="primary"  circle icon="el-icon-s-order" @click="$router.push(`/htlogin/sqb-details/${scope.row.apply_id}`)" ></el-button>
            <el-button size="small" type="danger" circle icon="el-icon-delete" @click="DeleteItem(scope.row.apply_id)"></el-button>
          </template>           
        </el-table-column>
      </el-table>
    </template>

    <br>
   
    
  </div>
</template>

<script>
import httpApi from "@/http";
  export default {
     data(){
        return{
          name:'',
          apply:[],
        }
     },
     methods:{
      // 删除电影列表
      DeleteItem(apply_id){
        // 弹窗
        this.$confirm('此操作将永久删除用户信息, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          
          // 确定
          httpApi.ApplyApi.delete({apply_id}).then(res =>{
            if(res.data.code == 200){
               console.log("删除成功",res);
              // 提醒用户删除成功
              this.$message({ type: 'success', message: '删除成功!' });
              // 刷新
              this.search()
            }else{
              // 提醒用户删除失败
              this.$message.error('错了哦，删除失败');
            }
           
          })
        }).catch(() => {
            this.$message({ type: 'info', message: '已取消删除' });          
          });
        },

        // 点击查询按钮后执行，需要判断输入框中是否有关键字
        //trim()是去掉字符串两端的空格
        search(){
          if(this.name.trim() == ''){
            //当无输入值
            this.listApply()
          }else{
            //有输入值
            this.listapplyByName()
            
          }
        },


        // 封装用户列表
        listApply(){
          httpApi.ApplyApi.queryApplyList().then(res =>{
            console.log("申请列表",res);
            this.apply = res.data.data
          })
        },
         

        // 通过姓名关键字查询演员列表
        listapplyByName(){
          let params = {name:this.name.trim()}
            httpApi.ApplyApi.queryApplyByNameLike(params).then(res =>{
              console.log("申请模糊查询",res);
              this.apply = res.data.data.result
            })     
          }
        },

      // 页面挂载完毕后，发送请求，加载列表数据
      mounted(){
        //页面挂在完毕后，发送请求，加载列表数据
        this.listApply()
      }
  }
</script>

<style lang="scss" scoped>

</style>